package com.dries.netty.chat;

import com.dries.netty.chat.netty.WebSocketServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;
import java.net.UnknownHostException;

@EnableScheduling
@SpringBootApplication
public class NettyChatApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext run = SpringApplication.run(NettyChatApplication.class, args);

        Environment env = run.getEnvironment();
        try {
            String host = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");

            System.out.println("[----------------------------------------------------------]");
            System.out.println("聊天室启动成功！点击进入:\t http://" + host + ":" + port);
            System.out.println("[----------------------------------------------------------");

            WebSocketServer.getSingleInstance().start();

        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

    }

}
